package com.yyjj.hangqing.activity;

import android.os.Bundle;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.aries.ui.view.title.TitleBarView;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.vise.xsnow.http.ViseHttp;
import com.vise.xsnow.http.callback.ACallback;
import com.yyjj.hangqing.R;
import com.yyjj.hangqing.adapter.FundListAdapter;
import com.yyjj.hangqing.adapter.ZhiShuBaoAdapter;
import com.yyjj.hangqing.api.Api;
import com.yyjj.hangqing.entity.BaseTResp;
import com.yyjj.hangqing.entity.FundEntity;
import com.yyjj.hangqing.entity.ZhiShuBaoEntity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import tech.com.commoncore.app.FastManager;
import tech.com.commoncore.base.BaseRefreshLoadActivity;
import tech.com.commoncore.constant.ApiConstant;
import tech.com.commoncore.view.SpaceItemDecoration;

/**
 * 基金排行
 */
@Route(path = "/hq/PaiHang")
public class PaiHangActivity extends BaseRefreshLoadActivity{
    Date date = new Date();
    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("基金排行");
    }

    @Override
    public int getContentLayout() {
        return R.layout.hq_activity_zhi_shu_bao;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        mRecyclerView.addItemDecoration(new SpaceItemDecoration(1));

    }

    @Override
    public BaseQuickAdapter getAdapter() {
        return new FundListAdapter(R.layout.hq_item_fund_list);
    }

    @Override
    public void loadData(int page) {
        ViseHttp.GET(Api.HQ_URL)
                .baseUrl(ApiConstant.BASE_URL)
                .addParam("type","all")
                .addParam("st","desc")
                .addParam("number","50")
                .addParam("page",page+"")
                .addParam("sd",getTime(date))
                .addParam("ed",getTime(date))
                .request(new ACallback<BaseTResp<ArrayList<FundEntity>>>() {
                    @Override
                    public void onSuccess(BaseTResp<ArrayList<FundEntity>> data) {
                        if(data.code ==1){
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),data.data,null);
                        }else{
                            FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),null,null);
                        }
                    }

                    @Override
                    public void onFail(int errCode, String errMsg) {
                        FastManager.getInstance().getHttpRequestControl().httpRequestSuccess(getIHttpRequestControl(),null,null);
                    }
                });
    }
    //可根据需要自行截取数据显示
    public String getTime(Date date) {
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        return format.format(date);
    }
}
